<template>
  <div class="app-container">
    <el-form v-if="executeQuery" :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="交易号" prop="number">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入交易号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会员类型" prop="membertype">
      <el-select v-model="queryParams.membertype" placeholder="全部">
                      <el-option value="0" label="快递员"></el-option>
                      <el-option value="1" label="普通会员"></el-option>
                    </el-select>
       </el-form-item>
      <el-form-item label="支付渠道" prop="paymentChannel">
        <el-input
          v-model="queryParams.paymentChannel"
          placeholder="请输入支付渠道"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单号" prop="orderNumber">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="paymentStatus">
      <el-select v-model="queryParams.paymentStatus" placeholder="全部">
                      <el-option value="0" label="支付成功"></el-option>
                      <el-option value="1" label="尚未付款"></el-option>
                      <el-option value="2" label="支付失败"></el-option>
                    </el-select>
       </el-form-item>
      <el-form-item label="创建时间" prop="time1">
        <el-date-picker
          v-model="queryParams.time1"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
       <el-form-item label="手机号码" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
        />
      </el-form-item>
        <el-form-item label="订单类型" prop="orderType">
      <el-select v-model="queryParams.orderType" placeholder="全部">
                      <el-option value="0" label="派件/寄件"></el-option>
                      <el-option value="1" label="派件"></el-option>
                      <el-option value="2" label="寄件"></el-option>
                    </el-select>
       </el-form-item>
      <el-form-item label="完成时间" prop="time2">
        <el-date-picker
          v-model="queryParams.time2"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="text" @click="cancel1">取 消</el-button>
      </el-form-item>
    </el-form>
    <div class="flex-container">
    <el-button icon="el-icon-search"  @click="executeQuery =true" plain >高级搜索</el-button>
    </div>
    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['finance:payment:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['finance:payment:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['finance:payment:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['finance:payment:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="paymentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="交易号" align="center" prop="number" >
        <template slot-scope="scope">
          <span @click="handleDetail1(scope.row)" style="color:#6a9eff;text-decoration: underline;">{{scope.row.number}}</span>
        </template>
      </el-table-column>
       <el-table-column label="会员类型" align="center" prop="memberType" >
         <template slot-scope="scope">
          {{ scope.row.memberType == 0? '快递员' :"普通会员" }}
          </template>
      </el-table-column>
       <el-table-column label="手机号" align="center" prop="phone" >
         <template slot-scope="scope">
           <span @click="handleDetail2(scope.row)" style="color:#6a9eff;text-decoration: underline;">{{scope.row.phone}}</span>
         </template>
       </el-table-column>
      <el-table-column label="订单类型" align="center" prop="orderType" >
         <template slot-scope="scope">
          {{ scope.row.orderType == 0? '派件/寄件' : scope.row.orderType == 1? '派件':"寄件" }}
          </template>
      </el-table-column>
      <el-table-column label="订单号" align="center" prop="orderNumber" />
       <el-table-column label="应付金额" align="center" prop="payableAmount" >
         <template slot-scope="scope">
          ￥{{ scope.row.payableAmount}}
          </template>
       </el-table-column>
      <el-table-column label="支付渠道" align="center" prop="paymentChannel" >
        <template slot-scope="scope">
          {{ scope.row.paymentChannel == 1? '微信支付' : scope.row.paymentChannel == 2? '支付宝':"贝宝支付" }}
          </template>
      </el-table-column>
      <el-table-column label="支付币种" align="center" prop="paymentCurrency" />
      <el-table-column label="汇率" align="center" prop="rname" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180"/>
      <el-table-column label="付款时间" align="center" prop="paymentTime" width="180"/>
      <el-table-column label="支付状态" align="center" prop="paymentStatus" >
         <template slot-scope="scope">
          {{ scope.row.paymentStatus == 0? '支付成功' : scope.row.paymentStatus == 1? '尚未支付':"支付失败" }}
          </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改支付记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="交易号" prop="number">
          <el-input v-model="form.number" placeholder="请输入交易号" />
        </el-form-item>
        <el-form-item label="订单号" prop="orderNumber">
          <el-input v-model="form.orderNumber" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="支付渠道" prop="paymentChannel">
          <el-input v-model="form.paymentChannel" placeholder="请输入支付渠道" />
        </el-form-item>
        <el-form-item label="应付金额" prop="payableAmount">
          <el-input v-model="form.payableAmount" placeholder="请输入应付金额" />
        </el-form-item>
        <el-form-item label="优惠金额" prop="discountAmount">
          <el-input v-model="form.discountAmount" placeholder="请输入优惠金额" />
        </el-form-item>
        <el-form-item label="实际应付" prop="actualPayable">
          <el-input v-model="form.actualPayable" placeholder="请输入实际应付" />
        </el-form-item>
        <el-form-item label="支付币种" prop="paymentCurrency">
          <el-input v-model="form.paymentCurrency" placeholder="请输入支付币种" />
        </el-form-item>
        <el-form-item label="汇率" prop="exchangeRate">
          <el-input v-model="form.exchangeRate" placeholder="请输入汇率" />
        </el-form-item>
        <el-form-item label="创建时间" prop="creationTime">
          <el-date-picker clearable
            v-model="form.creationTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="付款账户" prop="paymentAccount">
          <el-input v-model="form.paymentAccount" placeholder="请输入付款账户" />
        </el-form-item>
        <el-form-item label="付款时间" prop="paymentTime">
          <el-date-picker clearable
            v-model="form.paymentTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择付款时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="汇率表外键" prop="did">
          <el-input v-model="form.did" placeholder="请输入汇率表外键" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPayment, getPayment, delPayment, addPayment, updatePayment } from "@/api/finance/payment";

export default {
  name: "Payment",
  data() {
    return {

       executeQuery:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 支付记录表格数据
      paymentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        number: null,
        orderType: null,
        orderNumber: null,
        paymentChannel: null,
        paymentStatus: null,
        createTime:null,
        completionTime:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleDetail1(row) {
      const id=row.id
      this.$router.push({path:"/finance/payment/details/role/"+id})
    },
    handleDetail2(row) {
      const id=row.id
      this.$router.push({path:"/personnel/courier-data/index/"+id})
    },
     cancel1() {
      this.executeQuery = false;
      this.reset();
    },
    /** 查询支付记录列表 */
    getList() {
      this.loading = true;
      listPayment(this.queryParams).then(response => {
        this.paymentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        number: null,
        orderType: null,
        orderNumber: null,
        paymentChannel: null,
        payableAmount: null,
        discountAmount: null,
        actualPayable: null,
        paymentCurrency: null,
        exchangeRate: null,
        creationTime: null,
        paymentAccount: null,
        paymentTime: null,
        paymentStatus: null,
        cid: null,
        did: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if(this.queryParams.time1!=null){
        const time1=this.queryParams.time1;
        this.queryParams.start1=time1[0];
        this.queryParams.end1=time1[1];
      }else{
        this.queryParams.start1=null;
        this.queryParams.end1=null;
      }
      if(this.queryParams.time2!=null){
        const time2=this.queryParams.time2;
        this.queryParams.start2=time2[0];
        this.queryParams.end2=time2[1];
      }else{
        this.queryParams.start2=null;
        this.queryParams.end2=null;
      }
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加支付记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPayment(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改支付记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePayment(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPayment(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除支付记录编号为"' + ids + '"的数据项？').then(function() {
        return delPayment(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('finance/payment/export', {
        ...this.queryParams
      }, `payment_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
.flex-container {
  display: flex;
  justify-content: center;
}
</style>
